<template>
  	<view class="content">

  		<button @tap="login()" type="primary">点击微信登录</button>
	
  	</view>
</template>

<script>
import{loging,getInfo, login} from '../api/login.js'
  export default {
    data() {
      return {
		sessionKey: ''
      }
    },
    methods: {
		async login(){
						let that = this //保存当前作用域
						await uni.login({ //直接用这个调用微信接口
							onlyAuthorize:true,
							success:function(response){ // 用微信登录的话就要去微信开发工具
							login(response.code).then(res=>{
								uni.setStorageSync("App-Token",res.token)
								console.log(res.token)
							})
							}
						})
						
						await uni.getUserProfile ({
							desc: '获取微信头像跟网名',
								success:function(res){
									uni.request({
										url: 'https://www.allgays.love:8088/wx/user/getUserInfo',
										method: 'POST',
										dataType: 'json',
										data: {
											rawData: res.rawData,
											signature: res.signature,
											encryptedData: res.encryptedData,
											iv: res.iv,
											sessionKey: "",
											atoken: uni.getStorageSync("App-Token")
											},
										success(resc) {
											console.log(resc)
											uni.setStorageSync("nickName",resc.data.nickName)
											uni.setStorageSync("avaterUrl",resc.data.avatarUrl)
											uni.reLaunch({
												url:'/pages/mine/index'
											})
									}
								})
							}
						})
					
				},
    }
  }
</script>

<style lang="scss">
 .content{
 }
</style>
